<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<!-- head 头部-->
<head th:replace="admin/layout/include::head('日志记录','')"></head>

<body>
<!-- loading 动画-->
<div th:replace="admin/layout/include::loading"></div>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body ">

            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">账号：</label>
                        <div class="layui-input-inline mr0">
                            <input id="edtAccount" class="layui-input" type="text" placeholder="请输入账号"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">类型：</label>
                        <div class="layui-input-inline mr0">
                            <select name="type" id="type">
                                <option value=""></option>
                                <option value="1">业务</option>
                                <option value="2">登陆</option>
                                <option value="3">系统</option>
                                <option value="4">订单</option>
                                <option value="5">支付</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">日期：</label>
                        <div class="layui-input-inline mr0">
                            <input id="edtDate" class="layui-input date-icon" type="text" placeholder="请选择日期范围"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
                        <button id="btnExp" class="layui-btn icon-btn" ajax-event="export"><i class="layui-icon">&#xe67d;</i>导出</button>
                    </div>
                </div>
            </div>

            <table class="layui-table" id="logTable" lay-filter="logTable"></table>

        </div>
    </div>

</div>
<script type="text/html" id="toolbarOepration">
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-sm layui-btn-danger" ajax-event="batchDel" ajax-url="/admin/log/" >
            <i class="layui-icon layui-icon-delete"></i>批量删除</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" ajax-event="clearAll" ajax-url="/admin/log/clearAll/">
            <i class="layui-icon layui-icon-fonts-clear"></i>清空</button>
    </div>
</script>
</body>
<!-- js部分 -->
<div th:replace="admin/layout/include::js"></div>
<script>
    layui.use(['layer', 'form', 'table', 'util', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var laydate = layui.laydate;

        // 渲染表格
        var ins1 = table.render({
            elem: '#logTable',
            url: '/admin/log/',
            page: true,
            toolbar: '#toolbarOepration',
            height: 'full-100',
            limit: 15,
            limits: [15, 30, 50, 100],
            response: {
                countName: 'total'
            },
            loading : true,
            cols: [
                [
                {type: 'checkbox'},
                  {field:'id',title:'ID'},
                  {field:'name',title:'名称'},
                  {field:'type',title:'类型',templet:function (d) {
                          if (d.type == 1) {
                              return '<span class="layui-btn  layui-btn-xs layui-btn-radius layui-btn-warm"">业务</span>';
                          }else if(d.type==2){
                              return '<span class="layui-btn layui-btn-xs layui-btn-radius layui-bg-blue">登陆</span>';
                          }else{
                              return '<span class="layui-btn layui-btn-xs layui-btn-radius layui-btn-danger">系统</span>';
                          }
                      }},
                    {field:'model',title:'实体类'},
                    {field: 'method', title: '方法'},
                {field: 'recordId', title: '记录ID'},
                {field: 'message', title: '返回信息',minWidth:220},
                {field: 'ip', title: 'IP'},
                {field: 'operName', title: '操作用户'},
                {field: 'useTime', title: '用时(ms)'},
                {
                    templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '日志时间',minWidth:180
                }
            ]
            ]
        });

        // 时间范围
        laydate.render({
            elem: '#edtDate',
            type: 'datetime',
            range: true,
            theme: 'molv'
        });

        // 搜索按钮点击事件
        $('#btnSearch').click(function () {
            var searchDate = $('#edtDate').val().split(' - ');
            var searchAccount = $('#edtAccount').val();
            table.reload('logTable', {
                where: {
                    startDate: searchDate[0],
                    endDate: searchDate[1],
                    operName: searchAccount,
                    type: $('#type').val()
                }
            });
        });

        /*// 导出excel
        $('#btnExp').click(function () {
            var checkRows = table.checkStatus('logTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(ins1.config.id, checkRows.data, 'xls');
            }
        });*/

    });

</script>
</html>